package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.mapper.MemberMapper;
import com.itheima.mapper.OrderMapper;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: yyh
 * @Description:
 * @Date:Create：in 2020/7/2 21:42
 * @Modified By：
 */
@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberMapper memberMapper;

    @Autowired
    private OrderMapper orderMapper;
    //查询运营数据
    @Override
    public Map getBusinessReport() throws Exception {
        //01获取今日的日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());

        //获取本周一
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());

        //获取本月的第一天
        String firstDayThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //今日新增会员数
        Integer todayNewMenber = memberMapper.findTodayMember(today);
        //总会员数
        Integer totalMember = memberMapper.findTotalMember();
        //本周新增的会员数
        Integer thisWeekNewMember = memberMapper.findNewMemberCountAfterDate(thisWeekMonday);
        //本月新增的会员数
        Integer thisMonthNewMember = memberMapper.findNewMemberCountAfterDate(firstDayThisMonth);
        //今日预约数
        Integer todayOrderNumber = orderMapper.findTodayOrderNumber(today);
        //本周预约数
        Integer thisWeekOrderNumber = orderMapper.findOrderNumberAfterDate(thisWeekMonday);
        //本月预约数
        Integer thisMonthOrderNumber = orderMapper.findOrderNumberAfterDate(today);
        //今日到诊数
        Integer todayVisitsNumber = orderMapper.findTodayVisitsNumber(today);
        //本周到诊数
        Integer thisWeekVisitsNumber = orderMapper.findVisitsNumberAfterDate(thisWeekMonday);
        //本月到诊数
        Integer thisMonthVisitsNumber = orderMapper.findVisitsNumberAfterDate(firstDayThisMonth);
        //热门套餐4个
        List<Map<String, Object>> hotSetmeal = orderMapper.findHostSetmeal();

        //定义map封装页面所需要的数据
        HashMap<String, Object> result = new HashMap<>();
        /**
         *   reportDate: null,//报告日期
         *  todayNewMember: 0,//今日新增会员数
         *  totalMember: 0,//总会员数
         *  thisWeekNewMember: 0,//本周新增会员数
         *  thisMonthNewMember: 0,//本月新增会员数
         *  todayOrderNumber: 0,//今日预约数
         *  todayVisitsNumber: 0,//今日到诊数
         *  thisWeekOrderNumber: 0,//本周预约数
         *  thisWeekVisitsNumber: 0,//本周到诊数
         *  thisMonthOrderNumber: 0,//本月预约数
         *  thisMonthVisitsNumber: 0,//本月到诊数
         */
        result.put("reportDate",today);
        result.put("todayNewMember",todayNewMenber);
        result.put("totalMember",totalMember);
        result.put("thisWeekNewMember",thisWeekNewMember);
        result.put("thisMonthNewMember",thisMonthNewMember);
        result.put("todayOrderNumber",todayOrderNumber);
        result.put("todayVisitsNumber",todayVisitsNumber);
        result.put("thisWeekOrderNumber",thisWeekOrderNumber);
        result.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        result.put("thisMonthOrderNumber",thisMonthOrderNumber);
        result.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        result.put("hotSetmeal",hotSetmeal);
        return result;
    }
}
